package com.ws.game.common.framework
{
	import com.ws.game.common.global.Global;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	public class BaseGameScene extends Sprite
	{
		protected var objectList:Array;
		public function BaseGameScene(_stage:Stage)
		{
			super();
			Global.stage = _stage;
			Global.scene = this;
			objectList = new Array();
			Global.stage.addEventListener(Event.ENTER_FRAME, render);
		}
		
		public function get gObjects():Array{
			return objectList;
		}
		
		public function addGameObject(obj:BaseGameObject):void
		{
			if (objectList.indexOf(obj) != -1) 
				return; 
			objectList.push(obj);
			addChild(obj);
		}
		
		public function removeGameObject(obj:BaseGameObject):void
		{
			var id:int = objectList.indexOf(obj);
			if (id == -1) 
				return;
			objectList.splice(id,1);
			removeChild(obj);
			obj.dispose();
		}
		private var count:int=0;
		public function render(e:Event):void
		{
			for each(var obj:BaseGameObject in objectList) 
				obj.doWork();
		}
	}
}